// pages/member/msg-detail/msg-detail.js
var api = require('../../../utils/httpUtil.js');
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    id: 0,
    msg: {
      date: '',
      time: '',
      message: '',
      remark: '参加会议'
    }
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    var message = options.message;
    var date = options.date;
    var time = options.time;
    this.setData({
      'msg.message': message,
      'msg.date': date,
      'msg.time': time,
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  },

  loadData(id) {
    api.httpRequest(api.msgAPI + "/" + this.data.openId, {})
      .then(res => {
        if (res.code == 200) {
          var unReadList = res.data.filter(item => item.isRead === 0);
          unReadList.forEach(item => {
            item.date = item.createTime.substring(5, 10);
            item.time = item.createTime.substring(11, 16);
          });

          var readList = res.data.filter(item => item.isRead === 1);
          readList.forEach(item => {
            item.date = item.createTime.substring(5, 10);
            item.time = item.createTime.substring(11, 16);
          });

          this.setData({
            unReadMsgList: unReadList,
            readedMsgList: readList
          })
        }
      })
      .catch(error => {
        wx.showToast({
          title: error.message,
          duration: 1000,
          mask: true,
          icon: 'none'
        })
      });
  }
})